/box-generic-inline-create {       % =>
  box-container-create             % => Box
  dup box-generic-inline-setup-methods
  dup /box-generic-inline add-type
} def                              % => Box

/box-generic-inline-setup-methods {% => Box
  dup box-container-setup-methods
    
  dup get-box-dict /Methods get    % => Box Methods
  dup /maybe-line-break {box-generic-inline-maybe-line-break} put
  pop pop
} def

% Checks if current inline box should cause a line break inside the parent box
%
% @param $parent reference to a parent box
% @param $content flow context
% @return true if line break occurred; false otherwise
%
/box-generic-inline-maybe-line-break {
                                   % => Context Parent This
  1 index /line-break-allowed call-method {
% Calculate the x-coordinate of this box right edge
    1 index get-current-x
    1 index get-full-width
    add                            % => Context Parent This RightX

    false                          % => Context Parent This RightX NeedBreak

% Check for right-floating boxes
% If upper-right corner of this inline box is inside of some float, wrap the line
    3 index get-current-y
    2 index                        % => Context Parent This RightX NeedBreak CY X
    6 index
    context-point-in-floats
    /null ne                       % => Context Parent This RightX NeedBreak NeedBreak'
    or                             % => Context Parent This RightX NeedBreak

% No floats; check if we had run out the right edge of container
    3 index get-right
    rounding-epsilon add           % => Context Parent This RightX NeedBreak $parent->get_right()+EPSILON
    2 index le {                   % => Context Parent This RightX NeedBreak
        
% Now check if parent line box contains any other boxes;
% if not, we should draw this box unless we have a floating box to the left

      3 index
      box-container-get-first      % => Context Parent This RightX NeedBreak First

      4 index
      box-generic-calc-text-indent % => Context Parent This RightX NeedBreak First IndentOffset

      5 index get-current-x        % => Context Parent This RightX NeedBreak First IndentOffset CX
      6 index get-left             % => Context Parent This RightX NeedBreak First IndentOffset CX L
      2 index add
      rounding-epsilon add         % => Context Parent This RightX NeedBreak First IndentOffset CX X
      gt                           % => Context Parent This RightX NeedBreak First IndentOffset CX>X
      exch pop
      exch pop                     % => Context Parent This RightX NeedBreak CX>X
      or                           % => Context Parent This RightX NeedBreak'
    } if                           % => Context Parent This RightX NeedBreak

% As close-line will not change the current-Y parent coordinate if no 
% items were in the line box, we need to offset this explicitly in this case

    3 index get-line length 0 eq
    1 index and {                  % => Context Parent This RightX NeedBreak
      3 index get-current-y
      3 index get-height sub
      5 index put-current-y
    } if

    dup {
      4 index
      4 index box-container-close-line 
    } if                           % => Context Pareht This RightX NeedBreak

    exch pop
    exch pop
    exch pop
    exch pop
  } {
    pop pop pop false
  } ifelse
} def
